import 'package:aimaterials_app/model/Resource.dart';
import 'package:flutter/material.dart';
import 'package:aimaterials_app/common/localization/default_localizations.dart';
import 'package:aimaterials_app/common/style/gsy_style.dart';
import 'package:aimaterials_app/common/utils/common_utils.dart';
import 'package:aimaterials_app/common/utils/event_utils.dart';
import 'package:aimaterials_app/common/utils/navigator_utils.dart';
import 'package:aimaterials_app/model/RepoCommit.dart';
import 'package:aimaterials_app/widget/gsy_card_item.dart';
import 'package:aimaterials_app/widget/gsy_user_icon_widget.dart';
import 'package:aimaterials_app/model/Notification.dart' as Model;

/**
 * 事件Item
 * Created by guoshuyu
 * Date: 2018-07-16
 */
class GSYResourceItem extends StatelessWidget {
  final ResourceViewModel eventViewModel;

  final VoidCallback onPressed;

  final bool needImage;

  GSYResourceItem(this.eventViewModel, {this.onPressed, this.needImage = true})
      : super();

  @override
  Widget build(BuildContext context) {
    Widget des = (eventViewModel.resourceType == null ||
            eventViewModel.resourceType.length == 0)
        ? new Container()
        : new Container(
            child: new Text(
              eventViewModel.resourceType,
              style: GSYConstant.smallSubText,
              maxLines: 3,
            ),
            margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
            alignment: Alignment.topLeft);

    Widget userImage = (needImage)
        ? new GSYUserIconWidget(
            padding: const EdgeInsets.only(top: 0.0, right: 5.0, left: 0.0),
            width: 30.0,
            height: 30.0,
            image: eventViewModel.resourceName,
            onPressed: () {
              NavigatorUtils.goPerson(context, eventViewModel.resourceName);
            })
        : Container();
    return new Container(
      child: new GSYCardItem(
          child: new FlatButton(
              onPressed: onPressed,
              child: new Padding(
                padding: new EdgeInsets.only(
                    left: 0.0, top: 10.0, right: 0.0, bottom: 10.0),
                child: new Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    new Row(
                      children: <Widget>[
                        userImage,
                        new Expanded(
                            child: new Text(eventViewModel.resourceName,
                                style: GSYConstant.smallTextBold)),
//                        new Text(eventViewModel.resourceName,
//                            style: GSYConstant.smallSubText),
                      ],
                    ),
//                    new Container(
//                        child: new Text(eventViewModel.resourceUrl,
//                            style: GSYConstant.smallTextBold),
//                        margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
//                        alignment: Alignment.topLeft),
//                    des,
                  ],
                ),
              ))),
    );
  }
}

class ResourceViewModel {
  num resourceId;
  String resourceName;
  String resourceType;
  String resourceUrl;
  String preview;

  ResourceViewModel.fromResourceMap(Resource resource) {
    resourceId = resource.resourceId;
    preview = resource.preview;
    resourceType = resource.resourceType;
    resourceName =resource.resourceName??"--";
    resourceUrl = resource.resourceUrl??"--";
  }

}
